package basic.courseLearn01;

import basic.courseLearn01.utils.FunctionSort;
import basic.courseLearn01.utils.SortUtils;
import org.junit.Test;

//冒泡排序（从小到大）
public class BubbleSorting implements FunctionSort {

    //代码思路：每次循环最大的数往后移
    public int[] bubbleSort(int [] result){
        for (int i = 0; i < result.length-1; i++) {     //共进行n-1次循环
            for (int j = 0; j < result.length-i-1; j++) {
                if (result[j]>result[j+1]){
                    SortUtils.swap(result,j,j+1);
                }
            }
        }





        return result;
    }


    @Override
    public int[] sort(int[] result) {
        return bubbleSort(result);
    }

    @Test
    public void test(){
        SortUtils.executeCheckAlgorithm(1_0000,1000,1000,this);
    }


}
